﻿/****************************************************************************
Copyright (c) 2014-2015 凌惊雪 微信:Lingjingxue 邮箱:lingjingxue@sina.com QQ:271487457

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

using ServerBase.Other;
using ServerBase.Protocol;
using UtilPublic.ServerLoger;
using ServerBase.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UtilLib;

namespace ServerBase.Config
{
    /// <summary>
    /// 策划设置配置
    /// </summary>
    public static partial class Conf
    {
        

        #region 检查

        public static StringBuilder ConfSettingsCheckResult = new StringBuilder();
        public static void InitConfSettingsCheck()
        {
            ConfSettingsCheckResult.Clear();

            loger.Debug($"检查结果:");
            loger.Debug($"{ConfSettingsCheckResult}");
        }
        public static void CheckList(int Id, List<int> lists, bool rate = false)
        {
            if (rate)
            {
                if (lists.Count >= 4)
                {
                    var Award = new CLS_AwardItem()
                    {
                        Type = (short)lists[1],
                        ConfigId = lists[2],
                        Count = lists[3],
                    };
                    CheckAward(Id, Award);
                }
                else
                {
                    ConfSettingsCheckResult.AppendLine($"Id{Id} 项目小于4");
                }
            }
            else
            {
                if (lists.Count >= 3)
                {
                    var Award = new CLS_AwardItem()
                    {
                        Type = (short)lists[0],
                        ConfigId = lists[1],
                        Count = lists[2],
                    };
                    CheckAward(Id, Award);
                }
                else
                {
                    ConfSettingsCheckResult.AppendLine($"Id{Id} 项目小于3");
                }
            }
        }
        public static void CheckAward(int Id, CLS_AwardItem Award)
        {
            switch ((EAwardType)Award.Type)
            {
                //case EAwardType.道具:
                //    if (!ConfItem.ContainsKey(Award.ConfigId))
                //    {
                //        ConfSettingsCheckResult.AppendLine($"Id{Id} 道具ID {Award.ConfigId} 不存在");
                //    }
                //    break;
                //case EAwardType.装备:
                //    if (!ConfEquip.ContainsKey(Award.ConfigId))
                //    {
                //        ConfSettingsCheckResult.AppendLine($"Id{Id} 装备ID {Award.ConfigId} 不存在");
                //    }
                //    break;
                //case EAwardType.武将:
                //case EAwardType.绑定武将:
                //    if (!ConfWarrior.ContainsKey(Award.ConfigId))
                //    {
                //        ConfSettingsCheckResult.AppendLine($"Id{Id} 武将ID {Award.ConfigId} 不存在");
                //    }
                //    break;
                default:
                    break;
            }
        }
        #endregion

        /// <summary>
        /// 配置后续处理
        /// </summary>
        /// <returns></returns>
        public static bool InitConfSettingsExt()
        {
            //if (BaseServerInfo.SessionType == EServerType.中心)
            if (!BaseServerInfo.ServerRunModeIs外网)
            {
                InitConfSettingsCheck();
            }

            ConfGlobal = GlobalConf.ToDictionary
                (it => (EGlobalId)it.Value.GlobalId, it => new GlobalConfigExt(it.Value));

            ConfSurnameExt.Clear();
            ConfMalenameExt.Clear();
            ConfFemalenameExt.Clear();
            ConfBadwordsExt.Clear();
            switch (BaseServerInfo.Language)
            {
                case ELanguage.英语:
                    foreach (var item in ConfSurname.Values) { ConfSurnameExt.Add(item.LangEn); }
                    foreach (var item in ConfMalename.Values) { ConfMalenameExt.Add(item.LangEn); }
                    foreach (var item in ConfFemalename.Values) { ConfFemalenameExt.Add(item.LangEn); }
                    //foreach (var item in ConfBadwords.Values) { ConfBadwordsExt.Add(item.LangEn); }
                    break;
                case ELanguage.韩语:
                    foreach (var item in ConfSurname.Values) { ConfSurnameExt.Add(item.LangKo); }
                    foreach (var item in ConfMalename.Values) { ConfMalenameExt.Add(item.LangKo); }
                    foreach (var item in ConfFemalename.Values) { ConfFemalenameExt.Add(item.LangKo); }
                    //foreach (var item in ConfBadwords.Values) { ConfBadwordsExt.Add(item.LangKo); }
                    break;
                default:
                    foreach (var item in ConfSurname.Values) { ConfSurnameExt.Add(item.LangChs); }
                    foreach (var item in ConfMalename.Values) { ConfMalenameExt.Add(item.LangChs); }
                    foreach (var item in ConfFemalename.Values) { ConfFemalenameExt.Add(item.LangChs); }
                    foreach (var item in ConfBadwords.Values) { ConfBadwordsExt.Add(item.LangChs); }
                    break;
            }

            ConfDropExt = ConfDrop.ToDictionary
                (it => it.Value.Id, it => new ConfigDropExt(it.Value));

            ConfRoomExt = ConfRoom.ToDictionary
                (it => it.Value.Id, it => new ConfigRoomExt(it.Value));

            ConfCityRoom.Clear();
            foreach (var item in ConfRoom.Values)
            {
                ConfCityRoom.TryAdd(item.City, item.Id);
            }

            ConfListUsage = Util.GetValues<EUsageType>();

            ConfWeaponTypeExt = ConfWeaponType.ToDictionary
               (it => (EWeaponType)(it.Value.WeaponType), it => new ConfigWeaponTypeExt(it.Value));

            ConfRaceExt = ConfRace.ToDictionary
               (it => (ERace)(it.Value.Race), it => new ConfigRaceExt(it.Value));

            ConfSkillActionExt.Clear();
            foreach (var item in ConfCbtAction.Values)
            {
                if (item.ActionType != "skill")
                {
                    continue;
                }
                if (item.Perform.IsNullOrEmpty(true))
                {
                    ConfSkillActionExt.TryAdd(item.SkillId, item);
                }
            }

            ConfSkillDodgeExt.Clear();
            foreach (var item in ConfSkillDodge.Values)
            {
                ConfSkillDodgeExt.TryAdd(item.SkillId, item.Desc);
            }

            ConfSkillParryExt.Clear();
            foreach (var item in ConfSkillParry.Values)
            {
                ConfSkillParryExt.TryAdd(item.SkillId, item.Desc);
            }

            ConfCbtDamageExt.Clear();
            foreach (var item in ConfCbtDamage.Values)
            {
                foreach (var item2 in item.DamageType)
                {
                    ConfCbtDamageExt.TryAdd(item2, item);
                }
            }

            return true;
        }

    }

}